﻿Public Class ImatgeText
    Inherits ContentControl

    Public Shared ReadOnly TitleProperty As DependencyProperty = _
        DependencyProperty.Register("Title", _
        GetType(String), _
        GetType(ImatgeText), _
        Nothing)

    Public Property Title() As String
        Get
            Return CStr(GetValue(TitleProperty))
        End Get
        Set(ByVal value As String)
            SetValue(TitleProperty, value)
        End Set
    End Property

    Public Shared ReadOnly IconProperty As DependencyProperty = _
        DependencyProperty.Register("Icon", _
        GetType(System.Windows.Media.ImageSource), _
        GetType(ImatgeText), _
        Nothing)

    Public Property Icon() As System.Windows.Media.ImageSource
        Get
            Return DirectCast(GetValue(IconProperty), System.Windows.Media.ImageSource)
        End Get
        Set(ByVal value As System.Windows.Media.ImageSource)
            SetValue(IconProperty, value)
        End Set
    End Property


#Region "Visual State Manager"
    Private Sub ImatgeText_GotFocus(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.GotFocus
        VisualStateManager.GoToState(sender, "Focused", True)
    End Sub

    Private Sub ImatgeText_LostFocus(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.LostFocus
        VisualStateManager.GoToState(sender, "Unfocused", True)
    End Sub

    Private Sub ImatgeText_IsEnabledChanged(sender As Object, e As System.Windows.DependencyPropertyChangedEventArgs) Handles Me.IsEnabledChanged
        If DirectCast(e.NewValue, Boolean) Then
            VisualStateManager.GoToState(sender, "Normal", True)
        Else
            VisualStateManager.GoToState(sender, "Disabled", True)
        End If
    End Sub

    Private Sub ImatgeText_MouseEnter(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles Me.MouseEnter
        VisualStateManager.GoToState(sender, "MouseOver", True)
    End Sub

    Private Sub ImatgeText_MouseLeave(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles Me.MouseLeave
        VisualStateManager.GoToState(sender, "Normal", True)
    End Sub

    Private Sub ImatgeText_MouseLeftButtonDown(sender As Object, e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
        VisualStateManager.GoToState(sender, "Pressed", True)
    End Sub

    Private Sub ImatgeText_MouseLeftButtonUp(sender As Object, e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
        VisualStateManager.GoToState(sender, "Normal", True)

        If IsTabStop Then
            Me.Focus()
        End If
    End Sub
#End Region

End Class
